package com.foreveredu.propms.service.impl;

import java.util.List;

import org.springframework.transaction.annotation.Transactional;

import com.foreveredu.propms.domain.BuildingType;
import com.foreveredu.propms.domain.ChargeCriterion;
import com.foreveredu.propms.domain.ChargeItem;
import com.foreveredu.propms.domain.ChargeRecord;
import com.foreveredu.propms.domain.ChargeUnit;
import com.foreveredu.propms.domain.ChargeWay;
import com.foreveredu.propms.domain.House;
import com.foreveredu.propms.domain.HouseSource;
import com.foreveredu.propms.domain.HouseType;
import com.foreveredu.propms.domain.PageModel;
import com.foreveredu.propms.domain.ParkLocation;
import com.foreveredu.propms.domain.SinglePropertyChargeCriterion;
import com.foreveredu.propms.domain.SubDistrict;
import com.foreveredu.propms.persist.IChargeCriterionDao;
import com.foreveredu.propms.persist.IChargeItemDao;
import com.foreveredu.propms.persist.IChargeRecordDao;
import com.foreveredu.propms.persist.IChargeUnitDao;
import com.foreveredu.propms.persist.IChargeWayDao;
import com.foreveredu.propms.persist.IParkLocationDao;
import com.foreveredu.propms.persist.ISinglePropertyChargeCriterionDao;
import com.foreveredu.propms.service.IChargeService;

@Transactional
public class ChargeService implements IChargeService {

	private IChargeItemDao chargeItemDao = null;
	private IChargeCriterionDao chargeCriterionDao = null;
	private IChargeRecordDao chargeRecordDao = null;
	private IChargeWayDao chargeWayDao = null;
	private IChargeUnitDao chargeUnitDao = null;
	private IParkLocationDao parkLocationDao = null;
	private ISinglePropertyChargeCriterionDao spChargeCriterionDao = null;

	public IChargeItemDao getChargeItemDao() {
		return chargeItemDao;
	}

	public void setChargeItemDao(IChargeItemDao chargeItemDao) {
		this.chargeItemDao = chargeItemDao;
	}

	public IChargeCriterionDao getChargeCriterionDao() {
		return chargeCriterionDao;
	}

	public void setChargeCriterionDao(IChargeCriterionDao chargeCriterionDao) {
		this.chargeCriterionDao = chargeCriterionDao;
	}

	public IChargeRecordDao getChargeRecordDao() {
		return chargeRecordDao;
	}

	public void setChargeRecordDao(IChargeRecordDao chargeRecordDao) {
		this.chargeRecordDao = chargeRecordDao;
	}

	public IChargeWayDao getChargeWayDao() {
		return chargeWayDao;
	}

	public void setChargeWayDao(IChargeWayDao chargeWayDao) {
		this.chargeWayDao = chargeWayDao;
	}

	public IChargeUnitDao getChargeUnitDao() {
		return chargeUnitDao;
	}

	public void setChargeUnitDao(IChargeUnitDao chargeUnitDao) {
		this.chargeUnitDao = chargeUnitDao;
	}

	public IParkLocationDao getParkLocationDao() {
		return parkLocationDao;
	}

	public void setParkLocationDao(IParkLocationDao parkLocationDao) {
		this.parkLocationDao = parkLocationDao;
	}

	public ISinglePropertyChargeCriterionDao getSpChargeCriterionDao() {
		return spChargeCriterionDao;
	}
	
	public void setSpChargeCriterionDao(ISinglePropertyChargeCriterionDao spChargeCriterionDao) {
		this.spChargeCriterionDao = spChargeCriterionDao;
	}
	
	/*
	 * ChargeItem对象的事务处理
	 */
	public void saveChargeItem(ChargeItem chargeItem) {
		chargeItemDao.save(chargeItem);
	}

	public void deleteChargeItemById(int id) {
		ChargeItem ci = chargeItemDao.findById(id);
		chargeItemDao.delete(ci);
	}

	public void updateChargeItem(ChargeItem chargeItem) {
		chargeItemDao.update(chargeItem);
	}

	public List<ChargeItem> findChargeItems() {
		return chargeItemDao.findAll();
	}

	public ChargeItem findChargeItemById(int id) {
		return chargeItemDao.findById(id);
	}

	public ChargeItem findChargeItemByName(String name) {
		return chargeItemDao.findByName(name);
	}
	
	@Override
	public ChargeItem findChargeItemByItemId(String itemId) {
		return chargeItemDao.findChargeItemByItemId(itemId);
	}

	/*
	 * ChargeCriterion对象的事务处理
	 */
	public void saveChargeCriterion(ChargeCriterion chargeCriterion) {
		chargeCriterionDao.save(chargeCriterion);
	}

	public void deleteChargeCriterionById(int id) {
		ChargeCriterion cc = chargeCriterionDao.findById(id);
		chargeCriterionDao.delete(cc);
	}

	public void updateChargeCriterion(ChargeCriterion chargeCriterion) {
		chargeCriterionDao.update(chargeCriterion);
	}

	public List<ChargeCriterion> findChargeCriterions() {
		return chargeCriterionDao.findAll();
	}

	public ChargeCriterion findChargeCriterionById(int id) {
		return chargeCriterionDao.findById(id);
	}

	/*
	 * ChargeRecord对象的事务处理
	 */
	public void saveChargeRecord(ChargeRecord chargeRecord) {
		chargeRecordDao.save(chargeRecord);
	}

	public void deleteChargeRecordById(int id) {
		ChargeRecord cr = chargeRecordDao.findById(id);
		chargeRecordDao.delete(cr);
	}

	public void updateChargeRecord(ChargeRecord chargeRecord) {
		chargeRecordDao.update(chargeRecord);
	}

	public List<ChargeRecord> findChargeRecords() {
		return chargeRecordDao.findAll();
	}

	public ChargeRecord findChargeRecordById(int id) {
		return chargeRecordDao.findById(id);
	}

	/*
	 * ChargeWay对象的事务处理
	 */
	@Override
	public List<ChargeWay> findChargeWays() {
		return chargeWayDao.findAll();
	}

	@Override
	public void saveChargeWay(ChargeWay chargeWay) {
		chargeWayDao.save(chargeWay);

	}

	@Override
	public void deleteChargeWayById(int id) {
		chargeWayDao.delete(chargeWayDao.findById(id));
	}

	@Override
	public ChargeWay findChargeWayById(int id) {
		return chargeWayDao.findById(id);
	}

	@Override
	public void updateChargeWay(ChargeWay chargeWay) {
		chargeWayDao.update(chargeWay);
	}

	/*
	 * ChargeUnit对象的事务处理
	 */
	@Override
	public void deleteChargeUnitById(int id) {
		ChargeUnit cu = chargeUnitDao.findById(id);
		chargeUnitDao.delete(cu);
	}

	@Override
	public ChargeUnit findChargeUnitById(int id) {
		return chargeUnitDao.findById(id);
	}

	@Override
	public List<ChargeUnit> findChargeUnits() {
		return chargeUnitDao.findAll();
	}

	@Override
	public void saveChargeUnit(ChargeUnit chargeUnit) {
		chargeUnitDao.save(chargeUnit);
	}

	@Override
	public void updateChargeUnit(ChargeUnit chargeUnit) {
		chargeUnitDao.update(chargeUnit);
	}

	/*
	 * ParkLocation对象的事务处理
	 */
	@Override
	public List<ParkLocation> findParkLocations() {
		return parkLocationDao.findAll();
	}

	@Override
	public void saveParkLocation(ParkLocation parkLocation) {
				parkLocationDao.save(parkLocation);		
	}

	@Override
	public void deleteParkLocationById(int id) {
				parkLocationDao.delete(parkLocationDao.findById(id));
	}

	@Override
	public ParkLocation findParkLocationById(int id) {
		return parkLocationDao.findById(id);
	}

	@Override
	public void updateParkLocation(ParkLocation parkLocation) {
				parkLocationDao.update(parkLocation);
	}

	/*
	 * SinglePropertyChargeCriterion对象的事务处理
	 */
	@Override
	public void deleteSinglePropertyChargeCriterionById(int id) {
		SinglePropertyChargeCriterion spCriterion = spChargeCriterionDao.findById(id);
		spChargeCriterionDao.delete(spCriterion);
	}

	@Override
	public SinglePropertyChargeCriterion findSinglePropertyChargeCriterionById(int id) {
		return spChargeCriterionDao.findById(id);
	}

	@Override
	public List<SinglePropertyChargeCriterion> findSinglePropertyChargeCriterions() {
		return spChargeCriterionDao.findAll();
	}

	@Override
	public void saveSinglePropertyChargeCriterion(SinglePropertyChargeCriterion chargeCriterion) {
		spChargeCriterionDao.save(chargeCriterion);
	}

	@Override
	public void updateSinglePropertyChargeCriterion(SinglePropertyChargeCriterion chargeCriterion) {
		spChargeCriterionDao.update(chargeCriterion);
	}

	@Override
	public List<ChargeCriterion> findSingleChargeCriterions() {
		return chargeCriterionDao.findSingleChargeCriterions();
	}

	@Override
	public List<ChargeCriterion> findPrimaryChargeCriterions() {
		return chargeCriterionDao.findPrimaryChargeCriterions();
	}

	@Override
	public ChargeCriterion findCriterionByHouseAndItem(House house, ChargeItem item, SubDistrict subDistrict) {
		return chargeCriterionDao.findCriterionByHouseAndItem(house, item, subDistrict);
	}

	@Override
	public ChargeCriterion findCriterionByTypeAndItem(HouseType houseType, BuildingType buildingType, HouseSource source, ChargeItem item, SubDistrict subDistrict) {
		return chargeCriterionDao.findCriterionByTypeAndItem(houseType, buildingType, source, item, subDistrict);
	}

	@Override
	public PageModel findChargeCriterionsList(int offset) {
		return chargeCriterionDao.findChargeCriterionsList(offset);
	}

	@Override
	public PageModel findSingChargeCriterionsList(int offset) {
		return chargeCriterionDao.findSingChargeCriterionsList(offset);
	}

	@Override
	public List<ChargeItem> findChargeItemsByType(int type) {
		return chargeItemDao.findChargeItemsByType(type);
	}

	@Override
	public void deleteChargeRecord(ChargeRecord chargeRecord) {
		chargeRecordDao.delete(chargeRecord);
	}

}
